package tests;

import processing.core.*;
import processing.data.*;

import java.util.*;

import de.fhpotsdam.unfolding.UnfoldingMap;
//import de.fhpotsdam.unfolding.examples.marker.labelmarker.LabeledMarker;
import de.fhpotsdam.unfolding.geo.Location;
import de.fhpotsdam.unfolding.utils.MapUtils;
import de.fhpotsdam.unfolding.providers.*;
import de.fhpotsdam.unfolding.marker.*;

/* not currently used
import de.fhpotsdam.unfolding.mapdisplay.*;
import de.fhpotsdam.unfolding.utils.*;
import de.fhpotsdam.unfolding.tiles.*;
import de.fhpotsdam.unfolding.interactions.*;
import de.fhpotsdam.unfolding.ui.*;
import de.fhpotsdam.unfolding.*;
import de.fhpotsdam.unfolding.core.*;
import de.fhpotsdam.unfolding.mapdisplay.shaders.*;
import de.fhpotsdam.unfolding.data.*;
import de.fhpotsdam.unfolding.geo.*;
import de.fhpotsdam.unfolding.texture.*;
import de.fhpotsdam.unfolding.events.*;
import de.fhpotsdam.utils.*;
import de.fhpotsdam.unfolding.providers.StamenMapProvider;
*/

@SuppressWarnings("serial")
public class simpleMap extends PApplet {
	
	int appWidth = 1024;
	int appHeight = 768;
	
	//GLOBAL FILE URLS
	String stationsCSV_URL = "../DataAssets/stationLocations.csv";
	 
    UnfoldingMap map;
    
    // declare maps for a few default providers
    UnfoldingMap msAerial;
    UnfoldingMap msRoad;
    UnfoldingMap stamenToner;
    UnfoldingMap osmGray;
    
    Location kcw = new Location(43.42f, -80.41f); // kcw (latitude, longitude) 
	
    float maxPanningDistance = 15;
    
    ArrayList<Marker> stationMarkers = new ArrayList<Marker>(); 
    
    public void setup() {
		size(appWidth, appHeight, P2D);
		
		// assign a few default map providers
		msAerial = new UnfoldingMap(this, new Microsoft.AerialProvider());
		msRoad = new UnfoldingMap(this, new Microsoft.RoadProvider());
		stamenToner = new UnfoldingMap(this, new StamenMapProvider.Toner());
		osmGray = new UnfoldingMap(this, new OpenStreetMap.OSMGrayProvider());
		
		map = stamenToner; // set map provider
		
		map.zoomAndPanTo(kcw, 12); // set map starting location and zoom level
		map.setPanningRestriction(kcw, maxPanningDistance); 
		map.setZoomRange(11, 19);
		
		MapUtils.createDefaultEventDispatcher(this, map); // creates default pan & zoom -- zoom in w/mouse wheel or dbl-click, out with "-"
		
		// load stations csv data into table
		Table stationtable = loadTable(stationsCSV_URL,"header");
		
		// read stations table data
		for (TableRow row : stationtable.rows()) {
			    
			String id = row.getString("ID"); 
		    float lon = row.getFloat("LONG");
		    float lat = row.getFloat("LAT");
		    String stationName = row.getString("NAME");
		    String type = row.getString("TYPE");
		    Location location = new Location(lat, lon);
		    
		    println("id: " + id + ", station: " + stationName + ", longitude: " + lon + ", latitude: " + lat + ", type: " + type);
		    
		    //create position marker
		    StationMarker stnMarker = new StationMarker(location);
	        println(stnMarker.getLocation());		 
		    
	        //add to list
		    stationMarkers.add(stnMarker); 
		    
		} 
		
		// add markers to map
		map.addMarkers(stationMarkers);
		
    }
		
    public void draw() {
        map.draw();

    }
   

    
//////////////// CLASSES ////////////////
   
    // station marker visualization
    public class StationMarker extends SimplePointMarker {
    	 
    	  public StationMarker(Location location) {
    	    super(location);
    	  }
    	 
    	  public void draw(PGraphics pg, float x, float y) {
    	    pg.pushStyle();
    	    pg.strokeWeight(5);
    	    pg.stroke (255,0,127);
    	    pg.noFill();
    	    pg.ellipse(x, y, 12, 12);
    	    pg.popStyle();
    	  }
    	}
    

}


